package tr.gov.tubitak.bilgem.esya.crlviewer;

import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ramazan.girgin
 * Date: 4/17/12
 * Time: 4:32 PM
 * To change this template use File | Settings | File Templates.
 */
public class ECrlFieldsModel extends DefaultTableModel{
    
    static final int MODEL_COLUMN_COUNT=2;
    static final int MODEL_COLUMN_NUM_FIELD_NAME=0;
    static final int MODEL_COLUMN_NUM_FIELD_VALUE=1;
    List<ECrlField> fieldList = new ArrayList<ECrlField>();
    public void loadFields(EViewerCRL viewerCRL){
        fieldList = viewerCRL.getCrlFields();
        fireTableDataChanged();
    }


    public ECrlField getRowField(int row){
        return fieldList.get(row);
    }
    @Override
    public int getRowCount() {
        if(fieldList == null){
            return 0;
        }
        return fieldList.size();
    }

    @Override
    public int getColumnCount() {
        return MODEL_COLUMN_COUNT;
    }

    @Override
    public String getColumnName(int column) {
        switch (column){
            case  MODEL_COLUMN_NUM_FIELD_NAME:
                return Bundle.getString("ECrlFieldsModel.alan");
            case MODEL_COLUMN_NUM_FIELD_VALUE:
                return  Bundle.getString("ECrlFieldsModel.deger");
            default:
                return "";
        }
    }

    @Override
    public Object getValueAt(int row, int column) {
        ECrlField eCrlField = fieldList.get(row);
        switch (column){
            case  MODEL_COLUMN_NUM_FIELD_NAME:
                return eCrlField.getName();
            case MODEL_COLUMN_NUM_FIELD_VALUE:
                return eCrlField.getValue();
            default:
                return "";
        }
    }

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }
}

